<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="keywords" content="">
		<meta name="description" content="">
		<title>用户注册</title>
		<link href="common-1.css" tppabs="http://www.xunron.cn/cases/hmshop/css/common.css" rel="stylesheet" />
		<link href="login-1.css" tppabs="http://www.xunron.cn/cases/hmshop/css/login.css" rel="stylesheet"  />
		<!--<script src="js/jquery-1.12.4.min.js"></script>-->
		<script  src="jquery-1.12.4.min.js" tppabs="http://code.jquery.com/jquery-1.12.4.min.js"></script>
	</head>
	<body>
		<header>
			<div id="head">
				<div class="logo">
					<a href="index.php.htm" tppabs="http://www.xunron.cn/cases/hmshop/index.php"><img src="logo-1.png" tppabs="http://www.xunron.cn/cases/hmshop/images/logo.png" /></a>
					<span>数码在线网上商城</span>
				</div>
				<div class="reg_text">
					<span>已有商城账号？<a href="login.php.htm" tppabs="http://www.xunron.cn/cases/hmshop/login.php">立即登录</a></span>
				</div>
			</div>
		</header>
		<section>
			<p class="reg_head">
				<span class="title">30秒快速注册,加入商城!</span>
			</p>
			<div class="reg_box">
				<div class="reg_form">
					<p class="form_tabs">
						<span>用手机注册</span>
					</p>
					<form action="" method="post" id="regForm" name="regForm">
						<div><label for="phone"><b>*</b>手机号：</label><input type="text" name="phone" id="phone" /><i></i></div>
						<p>请填写手机号码</p>
						<div><label for="code"><b>*</b>验证码：</label><input type="text" name="code" id="code" /><span><img src="code-1.jpg" tppabs="http://www.xunron.cn/cases/hmshop/images/code.jpg" /></span><i></i></div>
						<p>请填写图片验证码</p>
						<div><label for="phoneCode"><b>*</b>验证码：</label><input type="text" name="phoneCode" id="phoneCode" /><span id="msgCode">获取短信验证码</span><i></i></div>
						<p>请填写手机号码，然后点击[获取验证码]</p>
						<div><label for="userPwd"><b>*</b>密码：</label><input type="password" name="userPwd" id="userPwd" /><i></i></div>
						<p>6-16位字母和数字的组合，不可用特殊字符</p>
						<div><label for="userPwds"><b>*</b>验证密码：</label><input type="password" name="userPwds" id="userPwds" /><i></i></div>
						<p>再次输入密码</p>
						<p class="accept"><input type="checkbox" checked /> 同意 <a href="javascripta:;">《商城用户协议》</a></p>
						<p><input type="button" id="btnReg" class="img_submit" value="注册" /></p>
					</form>
				</div>
				<div class="fast_reg">
					<span>如果您已经注册，请 <a href="login.php.htm" tppabs="http://www.xunron.cn/cases/hmshop/login.php">直接登录</a> 或者用以下方式登录：</span>
					<p><a href="javascript:;" class="weibo"></a></p>
					<p><a href="javascript:;" class="qq"></a></p>
					<p><a href="javascript:;" class="pay"></a></p>
					<p><a href="javascript:;" class="baidu"></a></p>
				</div>
			</div>
			
		</section>
		<footer>
			<div id="foot">
				<span class="foot_link">
					<a href="javascript:;">关于HM商城</a> |
					<a href="javascript:;">联系我们</a> |
					<a href="javascript:;">帮助中心</a>
				</span>
				<span class="foot_copyscript">©2016. HM商城 版权所有</span>
			</div>
		</footer>
		<script>
			function nameFail(){
				var phone=regForm.phone.value;
				if(phone.trim()=='') {return;}
				var xhr=new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4&&xhr.status==200){
						if(xhr.responseText=='pass'){
							regForm.phone.nextElementSibling.innerHTML='恭喜,可以注册';
							regForm.phone.nextElementSibling.className="pass";
						}else{
							regForm.phone.nextElementSibling.innerHTML='手机号已被注册';
							regForm.phone.nextElementSibling.className="err";
							phone.focus();
						}
					}
				}
				xhr.open('GET','admin/reg_fail.php?tel='+phone,true);
				xhr.send(null);
			}
			$('#regForm').delegate('input','blur',formFail)
			function formFail(){
				if(phone.value.trim()==''){
					regForm.phone.nextElementSibling.innerHTML='请输入手机号码';
					regForm.phone.nextElementSibling.className="err";
					//regForm.phone.focus();
					console.log('1')
					return false;
					
				}else{
					//regForm.phone.nextElementSibling.innerHTML='';
					nameFail();
				}
				if(code.value.trim()==''){
					regForm.code.nextElementSibling.nextElementSibling.innerHTML='请输入验证码';
					regForm.code.nextElementSibling.nextElementSibling.className="err";
					//regForm.code.focus();
					console.log('2')
					return false;
					
				}else{
					regForm.code.nextElementSibling.nextElementSibling.innerHTML='';
				}
				if(phoneCode.value.trim()==''){
					regForm.phoneCode.nextElementSibling.nextElementSibling.innerHTML='请输入手机验证码';
					regForm.phoneCode.nextElementSibling.nextElementSibling.className="err";
					//regForm.phoneCode.focus();
					console.log('3')
					return false;
					
				}else{
					regForm.phoneCode.nextElementSibling.nextElementSibling.innerHTML='';
				}
				if(userPwd.value.trim()==''){
					regForm.userPwd.nextElementSibling.innerHTML='请输入登录密码';
					regForm.userPwd.nextElementSibling.className="err";
					//regForm.userPwd.focus();
					console.log('4')
					return false;
				}else{
					regForm.userPwd.nextElementSibling.innerHTML='';
				}
				if(userPwds.value.trim()==''||userPwds.value!=userPwd.value){
					regForm.userPwds.nextElementSibling.innerHTML='验证密码不相同';
					regForm.userPwds.nextElementSibling.className="err";
					//regForm.userPwds.focus();
					console.log('5')
					return false;
				}else{
					regForm.userPwds.nextElementSibling.innerHTML='';
				}
				return true;
			}
			btnReg.onclick=function(){
				var phone=regForm.phone.value;
				var code=regForm.code.value;
				var phoneCode=regForm.phoneCode.value;
				var userPwd=regForm.userPwd.value;
				var userPwds=regForm.userPwds.value;
				console.log(formFail());
				if(formFail()){
					$.post('reg_add.php'/*tpa=http://www.xunron.cn/cases/hmshop/admin/reg_add.php*/,{tel:phone,phoneCode:phoneCode,pwd:userPwd},function(txt){
						if(txt=='pass'){
							alert('注册成功!');
							location.href='login.php.htm'/*tpa=http://www.xunron.cn/cases/hmshop/login.php*/;
						}
					});
					//xhr.send('tel='+phone+'&phoneCode='+phoneCode+'&pwd='+userPwd);
				}
			}
		</script>
	</body>
</html>
